package com.qeado.admin.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qeado.admin.dao.UserInfoDao;
import com.qeado.admin.model.UserInfo;
import com.qeado.admin.service.UserInfoService;

@Service
public class UserInfoServiceImpl implements UserInfoService{
	@Autowired
	private UserInfoDao userInfoDao;

	public void deleteUser(String id) {
		userInfoDao.deleteUser(id);
	}

	public String saveUser(UserInfo userInfo) {
		if(userInfo.getId() != null && !"".equals(userInfo.getId())) {
			userInfoDao.updateUser(userInfo);
		} else {
			Object obj = userInfoDao.searchUserInfoByUsername(userInfo);
			if(obj != null)
				return "该用户名已存在！";
			userInfo.setId(UUID.randomUUID().toString());
			userInfoDao.saveUser(userInfo);
		}
		return null;
	}

	public UserInfo selectUser(String id) {
		return userInfoDao.selectUser(id);
	}

	public List<UserInfo> userSearch(UserInfo userInfo) {
		return userInfoDao.userSearch(userInfo);
	}

	@Override
	public List<UserInfo> searchUserCompanyList(UserInfo userInfo) {
		if("1".equals(userInfo.getUserCategory())){//1 means college user
			return userInfoDao.searchUserCollegeList(userInfo);
		} else {
			return userInfoDao.searchUserCompanyList(userInfo);
		}
	}

}
